<%--                                                                       --%>
<%-- Copyright (c) 2005 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>


<%@ page import =  "java.util.HashMap,
                    org.apache.commons.beanutils.PropertyUtils,
                    org.apache.struts.validator.DynaValidatorForm"
%>

<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<html-el:javascript formName="mtGroupEditForm"/>

<script language="javascript" src="<%=request.getContextPath()%>/mt/js/userPopup.js"></script>
<script language="JavaScript">
         
  function doCancel(theForm) {
    //var ok = confirm('<bean-el:message key="confirmCancel"  bundle="mt.messages"/>');
    if (theForm != null) {
      if (theForm.parentGroupFQN.value == "root"){
         theForm.groupFQN.value = theForm.parentGroupFQN.value; 
      }
      theForm.action = '<html-el:rewrite page="/mt/groupView.do" />';
      theForm.submit();
      return true;
    }
    return false;
  }

  function doReset(theForm) {
    if (theForm != null) {
      theForm.administrators.length = 0;
      <c:forEach var="oneUser" items="${mtGroupEditForm.map.originalAdmins}"  varStatus="status">
            var option = new Option(" ");
            option.text = '<c:out value="${oneUser}"/>';
            option.value = '<c:out value="${oneUser}"/>';
            theForm.administrators.options[<c:out value="${status.index}"/>] = option;
      </c:forEach>
    }
    return true;
  }

  function doSubmit(form) {
<c:if test="${!mtGroupEditForm.map.isLDAP}">
    if (form.groupName.value.indexOf("/") != -1) {
      alert("<bean-el:message key="mt.group.name.noSlash" bundle="mt.messages"/>");
      form.groupName.focus();
      return false;
    }
</c:if>
    var ret = validateMtGroupEditForm(form);
    if (ret == false)
      return false;
    var size = form.administrators.length;
    for (var index = 0; index < size ; index++) {
      form.administrators.options[index].selected = true;
    }
  }

  function doGroupParentAdministratorsView(url) {
    var popupWindow = window.open(url, "epGroupParentAdministrators", 'width=700,height=600,scrollbars=yes,resizable=yes');
    if (popupWindow != null) {
      if (popupWindow.opener == null) {
        popupWindow.opener = self;
      }
    }
    popupWindow.focus();
  }

</script>

<html-el:form action="/mt/groupSave.do" onsubmit="return doSubmit(this);">

<html-el:hidden name ="mtGroupEditForm" property="parentGroupFQN" />
<html-el:hidden name ="mtGroupEditForm" property="groupFQN" />
<html-el:hidden name ="mtGroupEditForm" property="originalGroupFQN" />
<html-el:hidden name ="mtGroupEditForm" property="edit" />

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">

        <div class="pageTitle">
          <c:if test="${!mtGroupEditForm.map.edit}">
            <bean-el:message key="mt.group.create.page.title" bundle="mt.messages"/>
          </c:if>
          <c:if test="${mtGroupEditForm.map.edit}">
            <bean-el:message key="mt.group.edit.page.title" bundle="mt.messages" arg0="${mtGroupEditForm.map.groupName}"/>
          </c:if>
        </div> 

	<div class="errorMessage"><html-el:errors bundle="mt.messages"/></div>

      <!-- end of PageTab -->			

<c:url var="parentAdminsUrl" value="/mt/groupParentAdministratorsView.do">
  <c:param name="groupFQN" value="${mtGroupEditForm.map.groupFQN}"/>
  <c:param name="originalGroupFQN" value="${mtGroupEditForm.map.originalGroupFQN}"/>
  <c:param name="edit" value="${mtGroupEditForm.map.edit}"/>
</c:url>
      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="mt.group.groupInfo" bundle="mt.messages"/></span>
        <c:if test="${!(mtGroupEditForm.map.readonly)}">
        <span class="right">
          <input type="button" class="titleButton" value="<bean-el:message key="button.group.inherited.administrators.view" bundle="mt.messages"/>" 
            onclick="doGroupParentAdministratorsView('<c:out value="${parentAdminsUrl}"/>')">
        </span>
       </c:if>
      </div>        
      
      <!--start main content area here-->
      <table width="100%" border="0" cellspacing="0" cellpadding="2">
        <tr>
          <!--Start page instructions(if any)-->
          <td height="1" class="pageInstructions">
            <br>
            <bean-el:message key="mt.group.create.instruction" bundle="mt.messages"/>
          </td>
          <!--End page instructions(if any)-->
        </tr>
      </table>

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="Process summary">
        <tr>
          <td class="label" width="30%">
             <bean-el:message key="mt.group.label.groupName" bundle="mt.messages"/>:
               <c:if test="${!(mtGroupEditForm.map.readonly)}">
                * 
               </c:if>  
          </td>
          <td class="labelField" width="70%">
            <c:choose>
              <c:when test="${mtGroupEditForm.map.isLDAP}">
                <c:out value="${mtGroupEditForm.map.groupName}"/>
                <html-el:hidden property="groupName"/>
              </c:when>
              <c:when test="${mtGroupEditForm.map.readonly}">  
                <c:out value="${mtGroupEditForm.map.groupName}"/>
                <html-el:hidden property="groupName"/>
              </c:when>
              <c:otherwise>  
                  <html-el:text maxlength="80" property="groupName" />
              </c:otherwise>
            </c:choose>
            &nbsp;
          </td>
        </tr>
        <tr>
          <td class="label" width="30%">
             <bean-el:message key="mt.group.label.administrators" bundle="mt.messages"/>:
          </td>
          <td class="labelField" width="70%">	
            <table>
              <tr>
                <td>
                  <html-el:select property="administrators" multiple="true" size="4" >
                    <html-el:options property="administrators"/>
                  </html-el:select>            
                </td>
                <td valign=top>
                  <input type="button" name="browse" class="pageButton" value='<bean-el:message key="button.browse" bundle="mt.messages"/>' onclick="JavaScript:userMultiSearchPopup('<html-el:rewrite page="/mt/userMultiSearchPopup.do"/>', 'mtGroupEditForm','administrators')" >
                </td>
              </tr>
            </table>
          </td>
        </tr>
       </table>
       <!--end main content area here-->

      <div class="pageButtonWrap" align="right">
          <html-el:reset styleClass="inputButton" property="resetBtn" onclick="return doReset(this.form)">
            <bean-el:message key="button.reset" bundle="mt.messages" />
	  </html-el:reset>
          &nbsp;
          &nbsp;
          <html-el:button styleClass="inputButton" property="cancelBtn" onclick="return doCancel(this.form)">
            <bean-el:message key="button.cancel" bundle="mt.messages"/>
          </html-el:button>
          <html-el:submit styleClass="inputButton" property="submitBtn">
            <bean-el:message key="button.save" bundle="mt.messages"/>
          </html-el:submit>
      </div>
    </td>
  </tr>
</table>

</html-el:form>

